home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group98b.txt
/
000111_icon-group-sender _Mon Jun 29 08:41:34 1998.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
3KB
Return-Path: <icon-group-sender>
Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
by baskerville.CS.Arizona.EDU (8.8.8/8.8.7) with SMTP id IAA06696
for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Mon, 29 Jun 1998 08:41:33 -0700 (MST)
Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
id AA21982; Mon, 29 Jun 1998 08:41:22 -0700
Sender: rwg@fns.com
Message-Id: <35970836.34465163@fns.com>
Date: Sun, 28 Jun 1998 23:21:26 -0400
From: Robbie Gilbert <rwg@fns.com>
Organization: Fujitsu Network Communications
X-Mailer: Mozilla 4.05 [en] (X11; I; SunOS 5.5.1 sun4u)
Mime-Version: 1.0
To: jeffery@segfault.cs.utsa.edu
Cc: icon-group@optima.CS.Arizona.EDU
Subject: Re: Forcing Generator to Return a List of Values
References: <199806270618.BAA10281@segfault.cs.utsa.edu>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Content-Length: 1928
Clinton Jeffery wrote:
> Hi,
>
> I am sure you got deluged with answers, so I will be brief. Yes, it is
> useful occasionally to collect all the results from a generator and put them
> in a list, and no, there isn't a standard library function. In fact, if you
> think about it, a library procedure would not help you. You need to write
> the code yourself, either in your own helper procedure, or directly in the
> place where you've got the generator and need the list. Fortunately, as you
> say, its only a couple of lines.
>
> Clint Jeffery
Clint,
Thanks for the response. Actually yours was the only one I've gotten so far.
I think a procedure can help; how about:
procedure collectAll (expressions)
local results
results := []
every C := !expressions do
every result := |@C do
results |||:= [result]
return results
end
This procedure is invoked using braces as explained on page 116 of the The Icon
Programming Language (3rd ed.), in the section on user-defined control
structures:
# args is some list
foo := collectAll { ! args }
This procedure takes a comma-separated list of co-expressions (in this example,
there is only one, !args), grabs all the results and returns them in a list.
(This may need some refinement to work properly for all kinds of expressions,
I just finished writing it so I haven't tested it thoroughly yet. Also the
list concatenation may not be very efficient--there may be a better way but I'm
new to this language.)
Hopefully I can pass any valid expression as an arg and get a list of the
results back. This is what I was trying to accomplish and seems to be fairly
general. This seems like a natural, common task and given Icon's strengths in
this type of thing I thought there would already be something like this in the
program library--didn't want to reinvent the wheel.
Thanks,
Robbie
rwg@fns.com